package it.stasbranger.myproject.dao;

import it.stasbranger.myproject.domain.Requests;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage Requests entities.
 * 
 */
@Repository("RequestsDAO")
@Transactional
public class RequestsDAOImpl extends AbstractJpaDao<Requests> implements
		RequestsDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { Requests.class }));

	/**
	 * EntityManager injected by Spring for persistence unit 
	 *
	 */
	@PersistenceContext(unitName = "")
	private EntityManager entityManager;

	/**
	 * Instantiates a new RequestsDAOImpl
	 *
	 */
	public RequestsDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findRequestsByDate
	 *
	 */
	@Transactional
	public Set<Requests> findRequestsByDate(java.util.Date date) throws DataAccessException {

		return findRequestsByDate(date, -1, -1);
	}

	/**
	 * JPQL Query - findRequestsByDate
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Requests> findRequestsByDate(java.util.Date date, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRequestsByDate", startResult, maxRows, date);
		return new LinkedHashSet<Requests>(query.getResultList());
	}

	/**
	 * JPQL Query - findRequestsByEmail
	 *
	 */
	@Transactional
	public Set<Requests> findRequestsByEmail(String email) throws DataAccessException {

		return findRequestsByEmail(email, -1, -1);
	}

	/**
	 * JPQL Query - findRequestsByEmail
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Requests> findRequestsByEmail(String email, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRequestsByEmail", startResult, maxRows, email);
		return new LinkedHashSet<Requests>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllRequestss
	 *
	 */
	@Transactional
	public Set<Requests> findAllRequestss() throws DataAccessException {

		return findAllRequestss(-1, -1);
	}

	/**
	 * JPQL Query - findAllRequestss
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Requests> findAllRequestss(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllRequestss", startResult, maxRows);
		return new LinkedHashSet<Requests>(query.getResultList());
	}

	/**
	 * JPQL Query - findRequestsByEmailContaining
	 *
	 */
	@Transactional
	public Set<Requests> findRequestsByEmailContaining(String email) throws DataAccessException {

		return findRequestsByEmailContaining(email, -1, -1);
	}

	/**
	 * JPQL Query - findRequestsByEmailContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Requests> findRequestsByEmailContaining(String email, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRequestsByEmailContaining", startResult, maxRows, email);
		return new LinkedHashSet<Requests>(query.getResultList());
	}

	/**
	 * JPQL Query - findRequestsByNameContaining
	 *
	 */
	@Transactional
	public Set<Requests> findRequestsByNameContaining(String name) throws DataAccessException {

		return findRequestsByNameContaining(name, -1, -1);
	}

	/**
	 * JPQL Query - findRequestsByNameContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Requests> findRequestsByNameContaining(String name, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRequestsByNameContaining", startResult, maxRows, name);
		return new LinkedHashSet<Requests>(query.getResultList());
	}

	/**
	 * JPQL Query - findRequestsByName
	 *
	 */
	@Transactional
	public Set<Requests> findRequestsByName(String name) throws DataAccessException {

		return findRequestsByName(name, -1, -1);
	}

	/**
	 * JPQL Query - findRequestsByName
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Requests> findRequestsByName(String name, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRequestsByName", startResult, maxRows, name);
		return new LinkedHashSet<Requests>(query.getResultList());
	}

	/**
	 * JPQL Query - findRequestsByIdrequests
	 *
	 */
	@Transactional
	public Requests findRequestsByIdrequests(Integer idrequests) throws DataAccessException {

		return findRequestsByIdrequests(idrequests, -1, -1);
	}

	/**
	 * JPQL Query - findRequestsByIdrequests
	 *
	 */

	@Transactional
	public Requests findRequestsByIdrequests(Integer idrequests, int startResult, int maxRows) throws DataAccessException {
		try {
			return executeQueryByNameSingleResult("findRequestsByIdrequests", idrequests);
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findRequestsByPrimaryKey
	 *
	 */
	@Transactional
	public Requests findRequestsByPrimaryKey(Integer idrequests) throws DataAccessException {

		return findRequestsByPrimaryKey(idrequests, -1, -1);
	}

	/**
	 * JPQL Query - findRequestsByPrimaryKey
	 *
	 */

	@Transactional
	public Requests findRequestsByPrimaryKey(Integer idrequests, int startResult, int maxRows) throws DataAccessException {
		try {
			return executeQueryByNameSingleResult("findRequestsByPrimaryKey", idrequests);
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(Requests entity) {
		return true;
	}
}
